/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import v4view.web.ext.BindingSelect;

public class FormEventsTests {
	@SuppressWarnings("rawtypes")
	private List<IFormEvents>	forms	= new ArrayList<IFormEvents>();

	@Before
	public void setup() {
		this.forms.add(new CheckBox());
		this.forms.add(new File());
		this.forms.add(new Hidden());
		this.forms.add(new InputButton());
		this.forms.add(new InputImage());
		this.forms.add(new Reset());
		this.forms.add(new Submit());
		this.forms.add(new Text());
		this.forms.add(new Password());
		this.forms.add(new Select());
		this.forms.add(new BindingSelect());
	}

	@Test
	public void checkEvents() {
		for (@SuppressWarnings("rawtypes")
		final IFormEvents e : this.forms) {
			this.checkOnBlur(e);
			this.checkOnChange(e);
			this.checkOnFocus(e);
			this.checkOnSelect(e);
		}
	}

	@SuppressWarnings("rawtypes")
	public void checkOnBlur(final IFormEvents e) {
		final String value = "checkOnBlur('hello');";
		final PageElement ele = e.setOnBlur(value);
		assertEquals(e, ele);
		assertEquals(value, e.getOnBlur());
	}

	@SuppressWarnings("rawtypes")
	public void checkOnChange(final IFormEvents e) {
		final String value = "checkOnChange('hello');";
		final PageElement ele = e.setOnChange(value);
		assertEquals(e, ele);
		assertEquals(value, e.getOnChange());
	}

	@SuppressWarnings("rawtypes")
	public void checkOnFocus(final IFormEvents e) {
		final String value = "checkOnFocus('hello');";
		final PageElement ele = e.setOnFocus(value);
		assertEquals(e, ele);
		assertEquals(value, e.getOnFocus());
	}

	@SuppressWarnings("rawtypes")
	public void checkOnSelect(final IFormEvents e) {
		final String value = "setOnSelect('hello');";
		final PageElement ele = e.setOnSelect(value);
		assertEquals(e, ele);
		assertEquals(value, e.getOnSelect());
	}
}
